package com.bqtv.sport.ui.main

import android.app.Activity
import android.content.Context
import android.content.Intent
import com.bqtv.sport.R
import com.bqtv.sport.app.AppActivity
import com.bqtv.sport.databinding.ActivityRestartBinding
import com.bqtv.sport.ui.MainActivity
import com.bqtv.sport.ui.SplashActivity

/**
 *    desc   : 重启应用
 */
class RestartActivity : AppActivity<ActivityRestartBinding>() {

    companion object {
        fun start(context: Context) {
            val intent = Intent(context, RestartActivity::class.java)
            if (context !is Activity) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            }
            context.startActivity(intent)
        }

        fun restart(context: Context) {
            val intent =
//                if (true) {
//                    // 如果是未登录的情况下跳转到闪屏页
//                    Intent(context, SplashActivity::class.java)
//                } else {
                // 如果是已登录的情况下跳转到首页
                Intent(context, SplashActivity::class.java)
//                }
            if (context !is Activity) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            }
            context.startActivity(intent)
        }
    }

    override fun initView() {}

    override fun initData() {
        restart(this)
        finish()
        toast(R.string.common_crash_hint)
    }

    override fun getViewBinding(): ActivityRestartBinding? {
        return ActivityRestartBinding.inflate(layoutInflater)
    }
}